OPC-UA attribute data (instances of UAAttributeData) can be formatted using standard or custom format strings.
Standard and custom format strings are supported by some overloads of the ToString method. For example, you can supply a format string to the ToString(String) and ToString(String, IFormatProvider) methods. Standard and custom format strings are also supported by the .NET Framework composite formatting feature, which is used by some Write and WriteLine methods of the Console and StreamWriter classes, the String.Format method, and the StringBuilder.AppendFormat method. The composite format feature allows you to include the string representation of multiple data items in a single string, to specify field width, and to align values in a field.A standard UAAttributeData format string has a form of a single alphabetic character called the format specifier. Any UAAttributeData format string that is not a standard format string is interpreted as a custom UAAttributeData format string. This includes strings that contain any whitespace before or after the standard format specifier.
The following table describes the standard format strings and displays sample output produced by each format specifier.
Format specifier | Name | Description | |
“b” | Brief (short) | Contains the value when it is present, the source timestamp, and the status code. | |
“B” | Brief (long) | Contains the value and its type (just the name) when the value is present, the source timestamp, and the status code. | |
“f” | Full (short) | Contains the value, the source and server timestamps, and the status code. | |
“F” | Full (long) | Contains the value and its type (full name), the source and server timestamps, and the status code. | |
“g” | General (short) | Contains the value when it is present, the source and server timestamps, and the status code. | |
“G” | General (long) | Contains the value and its type (just the name) when the value is present, the source and server timestamps, and the status code. |
You can create a custom UAAttributeData format string, which consists of one or more custom format specifiers, to define how to format the UAAttributeData. A custom UAAttributeData format string is any format string that is not a standard UAAttributeData format string.
The following table describes the custom format specifiers and displays sample output produced by some of the format specifiers.
Format specifier | Name | Description | |
Hbs | HasBadStatus | Value of the named property. | |
Hgs | HasGoodStatus | Value of the named property. | |
Hus | HasUncertainStatus | Value of the named property. | |
Hv | HasValue | Value of the named property. | |
O O(format) |
SourceTimestamp | Value of the named property, optionally formatted with format. | |
Ol Ol(format) |
SourceTimestampLocal | Value of the named property, optionally formatted with format. | |
R R(format) |
ServerTimestamp | Value of the named property, optionally formatted with format. | |
Rl Rl(format) |
ServerTimestampLocal | Value of the named property, optionally formatted with format. | |
S S(format) |
StatusCode | Value of the named property, optionally formatted with format. | |
V V(format) |
Value | Value of the named property, optionally formatted with format. | |
Vt |
ValueType | Value of the named property, optionally formatted with format. | |
\ | Escape character | Causes the next character to be interpreted as a literal rather than as a custom format specifier. | |
'string' "string" |
Literal string delimiter | Indicates that the enclosed characters should be copied to the result string unchanged. | |
; | Section separator | Defines sections with separate format. | |
Other | All other characters | The character is copied to the result string unchanged. |
The semicolon (;) is a conditional format specifier that applies different formatting to a value depending on the condition(s) it fulfills. To produce this behavior, a custom format string can contain up to two or more separated by semicolons. These sections are described in the following table.
Number of sections | Description |
1 | The format string applies to all values. |
2 | If the attribute data object contains (has) a value, section #2 applies. Otherwise, section #1 applies. |
>= 3 | Last 2 sections are taken as if there were just 2 sections. The preceding sections are ignored. |